package com.github.prontera.lisenter;

import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.SchedulerException;
import org.quartz.SchedulerListener;
import org.quartz.Trigger;
import org.quartz.TriggerKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component("daemonSchedulerListener")
public class DaemonSchedulerListener implements SchedulerListener {

	private static final Logger logger = LoggerFactory.getLogger(DaemonSchedulerListener.class);

	@Override
	public void jobScheduled(Trigger trigger) {
		logger.debug("部署新任务[{}]到队列[{}]中.", trigger.getKey().getName(), trigger.getKey().getGroup());
	}

	@Override
	public void jobUnscheduled(TriggerKey trigger) {
		logger.debug("移除队列[{}]中[{}]任务.", trigger.getGroup(), trigger.getName());
	}

	@Override
	public void triggerFinalized(Trigger trigger) {
		logger.debug("结束(生命周期)队列[{}]中[{}]任务.", trigger.getKey().getGroup(), trigger.getKey().getName());
	}

	@Override
	public void triggerPaused(TriggerKey triggerKey) {
		logger.debug("停止队列[{}]中[{}]任务.", triggerKey.getGroup(), triggerKey.getName());
	}

	@Override
	public void triggersPaused(String triggerGroup) {
		logger.debug("暂停队列[{}]全部任务.", triggerGroup);
	}

	@Override
	public void triggerResumed(TriggerKey trigger) {
		logger.debug("恢复队列[{}]中[{}]任务.", trigger.getGroup(), trigger.getName());
	}

	@Override
	public void triggersResumed(String triggerGroup) {
		logger.debug("恢复队列[{}]全部任务.", triggerGroup);
	}

	@Override
	public void jobAdded(JobDetail jobDetail) {
		logger.debug("添加队列[{}]中[{}]任务.", jobDetail.getKey().getGroup(), jobDetail.getKey().getName());
	}

	@Override
	public void jobDeleted(JobKey jobKey) {
		logger.debug("删除队列[{}]中[{}]任务.", jobKey.getGroup(), jobKey.getName());
	}

	@Override
	public void jobPaused(JobKey jobKey) {
		logger.debug("暂停队列[{}]中[{}]任务.", jobKey.getGroup(), jobKey.getName());
	}

	@Override
	public void jobsPaused(String jobGroup) {
		logger.debug("暂停队列[{}]中全部任务.", jobGroup);
	}

	@Override
	public void jobResumed(JobKey jobKey) {
		logger.debug("恢复队列[{}]中[{}]任务.", jobKey.getGroup(), jobKey.getName());
	}

	@Override
	public void jobsResumed(String jobGroup) {
		logger.debug("恢复队列[{}]全部任务.", jobGroup);
	}

	@Override
	public void schedulerError(String msg, SchedulerException cause) {
		logger.error("队列发生错误[{},{}].", msg, cause);
	}

	@Override
	public void schedulerInStandbyMode() {

	}

	@Override
	public void schedulerStarted() {
		logger.debug("任务队列已启动");
	}

	@Override
	public void schedulerStarting() {
		logger.debug("开始启动任务队列");
	}

	@Override
	public void schedulerShutdown() {
		logger.debug("任务队列已关闭");
	}

	@Override
	public void schedulerShuttingdown() {
		logger.debug("正在关闭任务队列");
	}

	@Override
	public void schedulingDataCleared() {
		logger.debug("清空任务队列所有的数据");
	}

}
